<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Framework_Request_Common
 *
 * @author      Joe Stump <joe@joestump.net>
 * @copyright   (c) 2005 2006 Joseph C. Stump. All rights reserved.
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @package     Framework
 * @filesource
 */

/**
 * Framework_Request_Common
 *
 * @author      Joe Stump <joe@joestump.net>
 * @package     Framework
 * @see         Framework::$request
 * @abstract
 */
abstract class Framework_Request_Common
{
	/**
	 * $module
	 *
	 * @access  public
	 * @var     string
	 */
	public $module = '';

	/**
	 * $class
	 *
	 * @access  public
	 * @var     string
	 */
	public $class = '';

	/**
	 * $event
	 *
	 * @access  public
	 * @var     string
	 */
	public $event = '__default';

	/**
	 * $presenter
	 *
	 * @access  public
	 * @var     string
	 */
	public $presenter = null;


	/**
	 * $getSanitized
	 *
	 * @access  public
	 * @var     array
	 */
	public $getSanitized;

	/**
	 * $postSanitized
	 *
	 * @access  public
	 * @var     array
	 */
	public $postSanitized;


	/**
	 * getHTTPPath
	 *
	 * @access public
	 * @return string The current HTTP path, e.g http://sitename.com/install/to/module/class/event
	 */
	public function getHTTPPath()
	{
		if (strlen($_SERVER['PATH_INFO']) || strlen($_SERVER['ORIG_PATH_INFO'])) {
			$requestString = strlen($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO']: $_SERVER['ORIG_PATH_INFO'];
			$requestString = htmlentities(trim($requestString,'/'), ENT_QUOTES);
			$installPath = Framework::$site->config('Framework','installPath');
			$actionPath = Framework::$site->config('Framework','actionPath');
			return 'http://'.$_SERVER['HTTP_HOST'].$installPath.$actionPath.$requestString;
        } else {
        	return '/'; //Framework::$site->selfURL();
        }
	}
	
	public function getHTTPFilePath()
	{
		$installPath = Framework::$site->config('Framework','installPath');
		return 'http://'.$_SERVER['HTTP_HOST'].$installPath;
		
	}

	/**
	 * getHTTPPath
	 *
	 * @access public
	 * @return string The base http path of the install
	 */
	public function getBaseHTTPPath()
	{
		$installPath = Framework::$site->config('Framework','installPath');
		$actionPath = Framework::$site->config('Framework','actionPath');
		return 'http://'.$_SERVER['HTTP_HOST'].$installPath.$actionPath;
	}

	/**
     * get
     *
     * Alternative to $_GET
     *
     * @access      public
     * @param		string		$item		Item to get
     * @return      mixed
     */
	public function get($item = null)
	{
		if (!$this->getSanitized) {
			$this->getSanitized = array();
			foreach($_GET as $key=>$value) {
				$this->getSanitized[$key] = htmlentities($_GET[$key]); 
			}
			
		}
			
		if ($item) {
			if(isset($this->getSanitized[$item])) {
				return $this->getSanitized[$item];
			} else {
				return false;
			}
		}

		return $this->getSanitized;
			
	}

	/**
     * isAjax
     *
     * Is this an ajax request?
     *
     * @access      public
     * @return      boolean
     */
	public function isAjax() {
		return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER ['HTTP_X_REQUESTED_WITH']  == 'XMLHttpRequest';
	}
}

?>
